﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter5.Section4
{
    public class Example02
    {
        public Example02()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double[], double> f
                = new V.Function.ToLastType<double[], double>(func);
            double[] from = { 1.0, 0.0 };
            double[] to = { 2.0, Math.Log(2.0)};
            V.IntegrationMultiD obj = new V.IntegrationMultiD(f, from, to);
            obj.Compute();
            result += obj.BestEstimation.ToString() + "\r\n";
            obj.NumberOfCall = 10000000;
            obj.Compute();
            result += obj.BestEstimation.ToString() + "\r\n";
            double a = 1.0 / 2.0 * (2.0 * Math.Sqrt(5.0) - Math.Sqrt(2.0) 
                + Math.Log((Math.Sqrt(5.0) + 2.0) / (Math.Sqrt(2.0) + 1.0))) 
                - 1.0 / 6.0 * (Math.Pow(5.0, 1.5) - Math.Pow(2.0, 1.5));
            result += a.ToString() + "\r\n";
        }
        private double func(double[] x)
        {
            if (x[1] > Math.Log(x[0])) return 0.0;
            else return (x[0]-1.0) * Math.Sqrt(1.0+Math.Exp(2.0*x[1]));
        }
    }
}
/* 
0.418097836958082
0.41810621971003
0.418106679934083
*/

